/* Zach Smith
 *
 * Project 1: Sort Algorithm Comparison
 *
 * RadixSort.java
 *
 */

import java.util.*;
import java.util.concurrent.*;

public class RadixSort {
    /***ConcurrentLinkedQueue Initialization***/
    //Uses ConcurrentLinkedQueues for "grouping" the array members by digits
    static private ConcurrentLinkedQueue<char[]> Ones = new ConcurrentLinkedQueue<char[]>();
    static private ConcurrentLinkedQueue<char[]> Twos = new ConcurrentLinkedQueue<char[]>();
    static private ConcurrentLinkedQueue<char[]> Threes = new ConcurrentLinkedQueue<char[]>();
    static private ConcurrentLinkedQueue<char[]> Fours = new ConcurrentLinkedQueue<char[]>();
    static private ConcurrentLinkedQueue<char[]> Fives = new ConcurrentLinkedQueue<char[]>();
    static private ConcurrentLinkedQueue<char[]> Sixes = new ConcurrentLinkedQueue<char[]>();
    static private ConcurrentLinkedQueue<char[]> Sevens = new ConcurrentLinkedQueue<char[]>();
    static private ConcurrentLinkedQueue<char[]> Eights = new ConcurrentLinkedQueue<char[]>();
    static private ConcurrentLinkedQueue<char[]> Nines = new ConcurrentLinkedQueue<char[]>();
    static private ConcurrentLinkedQueue <char[]> Zeros = new ConcurrentLinkedQueue<char[]>();
    
    public static void RadixSort(char[][] RadArray) {
        int maxSize = RadArray.length;
        
        /***Digit Loop***/
        for (int j = 8; j >= 0; j--) {
            /***Array Member Loop***/
            for (int i = 0; i < maxSize; i++) {
                /***Digit Grouping Switch***/
                switch(RadArray[i][j]) {
                    case '0':		Zeros.offer(RadArray[i]);
                    break;
                    case '1':		Ones.offer(RadArray[i]);
                    break;
                    case '2':		Twos.offer(RadArray[i]);
                    break;
                    case '3':		Threes.offer(RadArray[i]);
                    break;
                    case '4':		Fours.offer(RadArray[i]);
                    break;
                    case '5':		Fives.offer(RadArray[i]);
                    break;
                    case '6':		Sixes.offer(RadArray[i]);
                    break;
                    case '7':		Sevens.offer(RadArray[i]);
                    break;
                    case '8':		Eights.offer(RadArray[i]);
                    break;
                    case '9':		Nines.offer(RadArray[i]);
                    break;
                }
            }
            /***Counter to keep track of array position***/
            int Counter = 0;
            
            /***Places values from the queues into the array***/
            while (!Zeros.isEmpty()) {
                RadArray[Counter] = Zeros.remove();
                Counter++;
            }
            while (Ones.isEmpty() != true) {
                RadArray[Counter] = Ones.remove();
                Counter++;
            }
            while (Twos.isEmpty() != true) {
                RadArray[Counter] = Twos.remove();
                Counter++;
            }
            while (Threes.isEmpty() != true) {
                RadArray[Counter] = Threes.remove();
                Counter++;
            }
            while (Fours.isEmpty() != true) {
                RadArray[Counter] = Fours.remove();
                Counter++;
            }
            while (Fives.isEmpty() != true) {
                RadArray[Counter] = Fives.remove();
                Counter++;
            }
            while (Sixes.isEmpty() != true) {
                RadArray[Counter] = Sixes.remove();
                Counter++;
            }
            while (Sevens.isEmpty() != true) {
                RadArray[Counter] = Sevens.remove();
                Counter++;
            }
            while (Eights.isEmpty() != true) {
                RadArray[Counter] = Eights.remove();
                Counter++;
            }
            while (Nines.isEmpty() != true) {
                RadArray[Counter] = Nines.remove();
                Counter++;
            }
        }
    }
}